<?php

namespace app\api\controller;

use app\admin\model\ResumeBase;
use fast\Random;
use think\facade\Validate;
use think\facade\Config;
use app\common\library\Ems;
use app\common\library\Sms;
use app\common\controller\Api;

/**
 * 会员接口.
 */
class Jobseekers extends Api
{
    protected $noNeedLogin = ['',];
    protected $noNeedRight = '*';
    protected $user;

    public function _initialize()
    {
        parent::_initialize();
        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }
        $this->user = $this->auth->getUser();
    }

    /**
     * 会员中心.
     */
    public function index()
    {
        $this->success('', ['welcome' => $this->auth->nickname]);
    }


    //获取我的简历列表
    public function getresume_list(){
        $page = input("page",1);
        $page_size = input("pagesize",10);
        $user = $this->auth->getUser();
        $list = ResumeBase::where("user_id",$user->id)->paginate($page_size);
        $this->success("获取成功",$list);
    }

    public function saveresumebase(){
        $id = input("id");
        $save_data = [
            "user_id"=>$this->user->id,//姓名
            "name"=>input("name"),//姓名
            "title"=>input("title"),//标题
            "birth"=>input("birth"),//生日
            "age"=>input("age"), //年龄
            "email"=>input("email"), //电子邮箱
            "sex"=>input("sex"),//性别
            "mobile"=>input("mobile"),//手机号码
            "advantage"=>input("advantage"),//个人优势
            "job_class_id"=>input("job_class_id"), //职位
            "work_year"=>input("work_year"),
            "edu_type"=>input("edu_type"),
            "citystr"=>input("citystr"),
            "provicecode"=>input("provicecode"),
            "provicecodestr"=>input("provicecodestr"),
            "citycode"=>input("citycode"),
            "citycodestr"=>input("citycodestr"),
            "areacode"=>input("areacode"),
            "areacodestr"=>input("areacodestr"),
            "place_citystr"=>input("place_citystr"),
            "place_provicecode"=>input("place_provicecode"),
            "place_provicecodestr"=>input("place_provicecodestr"),
            "place_citycode"=>input("place_citycode"),
            "place_citycodestr"=>input("place_citycodestr"),
            "place_areacode"=>input("place_areacode"),
            "place_areacodestr"=>input("place_areacodestr"),
            "resume_files"=>input("resume_files"),
        ];
        foreach ($save_data as $k=>$v){
            if(!$v){
                unset($save_data[$k]);
            }
        }

        if(isset($_REQUEST["sex"])){   $save_data["sex"] = input("sex") ; }
        if(isset($_REQUEST["edu_type"])){   $save_data["edu_type"] = input("edu_type") ; }
        $resume_base_mod = new ResumeBase();
        if($id){
            $resume_base = $resume_base_mod->get($id);
            $resume_base->save($save_data);
        }else{
            $resume_base = $resume_base_mod->create($save_data);
        }
        $this->success("保存成功",$resume_base);
    }

}
